﻿@{
    Layout = null;
}
<div>
    <input type="button" id="btn_get" value="Get" onclick="Get()" />
    <input type="button" id="btn_get_param" value="GetParam" onclick="Get(1)" />
    <input type="button" id="btn_post" value="Post" onclick="Post()" />
    <input type="button" id="btn_put" value="Put" onclick="Put()" />
    <input type="button" id="btn_delete" value="Delete" onclick="Delete()" />
    <input type="button" id="btn_getaction" value="GetAction" onclick="GetAction()" />
    <input type="button" id="btn_postaction" value="PostAction" onclick="PostAction()" />
</div>
<script src="~/Scripts/jquery-1.8.2.js"></script>
<script type="text/javascript">
    function Get(id) {
        $.ajax({
            data: { name: "get" },
            type: 'GET',
            url: 'api/values/' + (typeof (id) != "undefined" ? id : ""),
            dataType: 'json',
            success: function (data) {
                alert(data);
            }
        });
    }
    function Post() {
        $.ajax({
            data: { "Name": "NiKlaus", "Age": "25" },
            //contentType: "application/json",
            type: 'Post',
            url: 'api/values/2?name1=post',
            dataType: 'json',
            success: function (objPerson) {
                alert(objPerson.Name);
            }
        });
    }
    function Put() {
        $.ajax({
            data: { "": "SonShining" },
            type: 'Put',
            url: 'api/values/25',
            dataType: 'json',
            success: function (data) {
                alert(JSON.stringify(data));
            }
        });
    }
    function Delete() {
        $.ajax({
            type: 'Delete',
            url: 'api/values/1',
            dataType: 'json',
            success: function (data) {

            }
        });
    }
    function GetAction() {
        $.ajax({
            type: 'Get',
            url: 'api/values/getperson?age=255&name=Ni',
            dataType: 'json',
            success: function (data) {
                alert(JSON.stringify(data));
            }
        });
    }
    function PostAction() {
        $.ajax({
            data: { "Name": "NiKlaus", "Age": "25" },
            type: 'Post',
            url: 'api/values/postperson?id=12',
            dataType: 'json',
            success: function (data) {
                alert(JSON.stringify(data));
            }
        });
    }
</script>